import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:riverpod_t/page/home/view/home_detail_page.dart';
import 'package:riverpod_t/routers/navigator_utils.dart';
import 'package:riverpod_t/routers/routers.dart';

class HomeNavigator {
  HomeNavigator._();

  static Future toHomeDetailPage(BuildContext context, {required String imageUrl}) {
    return NavigatorUtils.push(
      context,
      _HomeRoutes.homeDetailPage,
      replace: false,
      clearStack: false,
      arguments: {'imageUrl': imageUrl},
    );
  }

  static ModuleRouter getRouter() {
    return _HomeRoutes();
  }
}

class _HomeRoutes extends ModuleRouter {
  static const homeDetailPage = 'page/home/view/home_detail_page';

  @override
  void init(FluroRouter router) {
    router.define(
      homeDetailPage,
      handler: Handler(
        handlerFunc: (context, params) {
          Map? argument = context!.settings!.arguments as Map?;
          String imageUrl = argument?['imageUrl'] ?? '';
          return HomeDetailPage(imageUrl: imageUrl);
        },
      ),
    );
  }
}
